Skip to content

JavaScript: Consolidate Express tests.#1018

Merged
semmle-qlci merged 4 commits into
github:rc/1.20from
xiemaisi:js/consolidate-tests
Mar 4, 2019
Merged

JavaScript: Consolidate Express tests.#1018
semmle-qlci merged 4 commits into
github:rc/1.20from
xiemaisi:js/consolidate-tests

Conversation

@xiemaisi

@xiemaisi xiemaisi commented Mar 1, 2019

Copy link
Copy Markdown

An alternative proposal to #999, achieving much the same effect but with a slightly less intrusive and (almost) entirely automated transformation.

I've written a little utility (based on the QL frontend) that, given a folder with .ql files, does the following:

  1. Replace all select clauses with semantically equivalent query predicates, where the name of the query predicate is the name of the .ql file with test_ prepended to it.
  2. Rename all .ql files to .qll files.
  3. Create a new tests.ql file that imports all the .qll files created in the previous step.
  4. Concatenate all individual .expected files into one big tests.expected file, with the result for each query predicate preceded by its name (which is the format used by qltest for multi-query files).

The tool does all of these steps in one go, resulting in the second commit of this PR. To make it easier to review, however, I've then reverted that commit and added individual commits corresponding to the steps above. I'll remove those extra commits once everyone is happy.

As mentioned above, the whole process is almost entirely automated, except that the tool currently sometimes fails to construct valid qualified names for QL types (a non-trivial problem in the presence of modules). Since this only affects three of our Express tests I've opted for fixing it manually for now, but I'll try to get that sorted as well and then make the tool available to others.

Max Schaefer added 2 commits March 1, 2019 09:39
Instead of having many small independent tests, we now just have a single test that pulls in all the individual tests and runs them together.

Concretely, each `.ql` file has been turned into a `.qll` file with a query predicate corresponding to the original `select` clause and named after the original `.ql` file, plus a prefix `test_`.

The newly added `tests.ql` imports all these `.qll`s.

The individual `.expected` files have been concatenated together into `tests.expected`, each prefixed with the name of the corresponding query predicate. (This is the format that qltest produces for tests with multiple query predicates.)
@xiemaisi xiemaisi added JS WIP This is a work-in-progress, do not merge yet! labels Mar 1, 2019
@xiemaisi xiemaisi requested a review from a team as a code owner March 1, 2019 09:46

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a step that runs the autoformatter after the semantic transformation?

Minor, unrelated: import semmle.javascript.frameworks.ExpressModules is not required in the tests.

@xiemaisi

xiemaisi commented Mar 1, 2019

Copy link
Copy Markdown
Author

Can we have a step that runs the autoformatter after the semantic transformation?

Possibly, though for this PR I'll do it manually.

I'll also fix the unnecessary import.

@xiemaisi

xiemaisi commented Mar 1, 2019

Copy link
Copy Markdown
Author

Tests have passed, so unless there are objections I'd like to remove the extra commits, autoformat and fix the spurious import pointed out by @esben-semmle.

@ghost

ghost commented Mar 1, 2019

Copy link
Copy Markdown

Go ahead.

@xiemaisi xiemaisi force-pushed the js/consolidate-tests branch from ceb9b07 to 8e34092 Compare March 1, 2019 14:45
@xiemaisi xiemaisi removed the WIP This is a work-in-progress, do not merge yet! label Mar 1, 2019
@xiemaisi xiemaisi changed the base branch from master to rc/1.20 March 1, 2019 20:03
@xiemaisi xiemaisi added this to the 1.20 milestone Mar 1, 2019
@xiemaisi

xiemaisi commented Mar 4, 2019

Copy link
Copy Markdown
Author

Ping @esben-semmle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants